﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQExampleStudents
{
    class StudentsExample
    {
        static void Main()
        {
            List<Student> students = new List<Student>();
            students.Add(new Student("Mariya", "Luiza", 23));
            students.Add(new Student("Todor", "Aleksandrov", 25));
            students.Add(new Student("Aleksandyr", "Stamboliiski", 18));
            students.Add(new Student("Angel", "Kynchev", 15));
            students.Add(new Student("Todor", "Kableshkov", 20));
            
            List<Student> extractedStudentsByName = StudentMethods.ExtractStudentsByName(students).ToList<Student>();
            Console.WriteLine("Extracted students by name:");
            foreach (var item in extractedStudentsByName)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            List<Student> extractedStudentsByAge = StudentMethods.ExtractStudentsByAge(students).ToList<Student>();
            Console.WriteLine("Extracted students by age:");
            foreach (var item in extractedStudentsByAge)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            //sort with Extension Methods
            var sortedStudents = students.OrderBy(x => x.FirstName).ThenBy(y => y.LastName).ToList<Student>();
            
            //sort with LINQ
            //var sortedStudents = 
            //    from student in students
            //    orderby student.FirstName, student.LastName
            //    select student;

            foreach (Student student in sortedStudents)
            {
                Console.WriteLine(student);
            }
        }
    }
}
